package com.test.dataSource.service.impl;

import com.test.dataSource.config.SwitchDataSource;
import com.test.dataSource.mapper.testMapper;
import com.test.dataSource.mapper.testMapper1;
import com.test.dataSource.service.testService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.support.TransactionTemplate;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
@Service
public class testServiceImpl implements testService {
    @Autowired
    private testMapper testMapper;

    @Autowired
    private testMapper1 testMapper1;

    @Resource
    private TransactionTemplate transactionTemplate;

    @Override
    @SwitchDataSource(dataSource = "0")
    public List<Map<String, Object>> getAllStudents1() {
        return testMapper.getAllStudents();
    }

    @Override
    @SwitchDataSource(dataSource = "1")
    public List<Map<String, Object>> getAllStudents2() {
        return testMapper.getAllStudents();
    }

    @Override
    @SwitchDataSource(dataSource = "1")
    public List<Map<String, Object>> getAllStudents3() {
        return transactionTemplate.execute(status -> {
            return testMapper.getAllStudents();
        });
    }
}
